<?php
require_once dirname(__FILE__) . '/../config/config.php';
class GameCategoryController
{
    private $smarty;
    public function __construct()
    {
    }

    public function main(&$smarty)
    {
        $this->smarty = $smarty;
    }

    public function listAction()
    {
    	$_SESSION['timeout'] = time();
    	$context = new BaseContext();
        $result = new ServiceResult();
        $gameService = new GameService();
        $seo = new SEO();
        $gameCategoryService = new GameCategoryService();
        
        $pager = new Pager();
        
        $curpage = isset ($_GET['page']) ? $_GET['page'] : 1;
        
        if(isset($_GET['database']) && !empty($_GET['database']))
        {
        	$data = $_GET['database'];
        	
        	if($data == 'tpg')
        	{
        		$gameCategoryNameArr = $gameCategoryService -> getFullGameCategoryTPG($context, $result);
	        	if(isset($_POST) && !empty($_POST))
	        	{
		        	$filter = $_POST['filter'];
		        	if(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterParent')
		        	{
			        	$count = $gameCategoryService->countGameCategoryByParentTPG($context, $result, $filter);
			        	$limit = 100;
			        	$start = $pager->findStart($limit);
			        	$pages = $pager->findPages($count, $limit);
			        	$gameCategoryArr = $gameCategoryService->getGameCategoryByParentTPG($context, $result, $start, $limit, $filter);
			        	$lastStr = "controller=gameCategory&action=list&database=tpg&filter=filterParent";
		        	}
		        	elseif(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterID')
		        	{
		        		$gameCategoryArr = $gameCategoryService ->getGameCategoryByNameTPG($context, $result, $filter);
		        		$lastStr = "controller=gameCategory&action=list&database=tpg&filter=filterID";
		        	}
	        	}
	        	else 
	        	{
		        	$count = $gameCategoryService->countGameCategoryTPG($context, $result);
		        	$limit = 30;
		        	$start = $pager->findStart($limit);
		        	$pages = $pager->findPages($count, $limit);
		        	$gameCategoryArr = $gameCategoryService->getFullGameCategoryByLimitTPG($context, $result, $start, $limit);
		        	$lastStr = "controller=gameCategory&action=list&database=tpg";
	        	}
	        	
        	}
        	else if($data == 'mobile')
        	{
        		$gameCategoryNameArr = $gameCategoryService -> getFullGameCategoryMobile($context, $result);
	        	if(isset($_POST) && !empty($_POST))
	        	{
		        	$filter = $_POST['filter'];
		        	if(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterParent')
		        	{
			        	$gameCategoryArr = $gameCategoryService->getGameCategoryByParentMobile($context, $result,$filter);
			        	$lastStr = "controller=gameCategory&action=list&database=mobile&filter=filterParent";
		        	}
	        		elseif(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterID')
		        	{
		        		$gameCategoryArr = $gameCategoryService ->getGameCategoryByNameMobile($context, $result, $filter);
		        	}
	        	}
	        	else 
	        	{
		        	$count = $gameCategoryService->countGameCategoryMobile($context, $result);
		        	$limit = 30;
		        	$start = $pager->findStart($limit);
		        	$pages = $pager->findPages($count, $limit);
		        	$gameCategoryArr = $gameCategoryService->getFullGameCategoryByLimitMobile($context, $result, $start, $limit);
		        	$lastStr = "controller=gameCategory&action=list&database=mobile";
	        	}
	        	
        	}
	        else if($data == 'cgmb')
	        {
	        	$gameCategoryNameArr = $gameCategoryService -> getFullGameCategoryCGMB($context, $result);
	        	if(isset($_POST) && !empty($_POST))
	        	{
		        	$filter = $_POST['filter'];
		        	if(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterParent')
		        	{
			        	$count = $gameCategoryService->countGameCategoryByParentCGMB($context, $result, $filter);
			        	$limit = 100;
			        	$start = $pager->findStart($limit);
			        	$pages = $pager->findPages($count, $limit);
			        	$gameCategoryArr = $gameCategoryService->getGameCategoryByParentCGMB($context, $result, $start, $limit, $filter);
			        	$lastStr = "controller=gameCategory&action=list&database=tpg&filter=filterParent";
		        	}
	        		elseif (isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filter')
		        	{
		        		$lastStr = "controller=gameCategory&action=list&database=tpg&filter=filter";
		        		if($filter == 5)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsNewCGMB($context, $result);
		        		}
		        		elseif($filter == 6)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsPopCGMB($context, $result);
		        		}
		        		elseif($filter == 7)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByRankCGMB($context, $result);
		        		}
		        	}
	        		elseif(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterID')
		        	{
		        		$gameCategoryArr = $gameCategoryService ->getGameCategoryByNameCGMB($context, $result, $filter);
		        	}
	        	}
	        	else 
	        	{
		        	$count = $gameCategoryService->countGameCategoryCGMB($context, $result);
		        	$limit = 30;
		        	$start = $pager->findStart($limit);
		        	$pages = $pager->findPages($count, $limit);
		        	$gameCategoryArr = $gameCategoryService->getFullGameCategoryByLimitCGMB($context, $result, $start, $limit);
		        	$lastStr = "controller=gameCategory&action=list&database=cgmb";
	        	}
	        }
	        else if($data == 'nsgt')
	        {
	        	$gameCategoryNameArr = $gameCategoryService -> getFullGameCategoryNSGT($context, $result);
	        	if(isset($_POST) && !empty($_POST))
	        	{
		        	$filter = $_POST['filter'];
		        	if(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterParent')
		        	{
			        	$count = $gameCategoryService->countGameCategoryByParentNSGT($context, $result, $filter);
			        	$limit = 100;
			        	$start = $pager->findStart($limit);
			        	$pages = $pager->findPages($count, $limit);
			        	$gameCategoryArr = $gameCategoryService->getGameCategoryByParentNSGT($context, $result, $start, $limit, $filter);
			        	$lastStr = "controller=gameCategory&action=list&database=tpg&filter=filterParent";
		        	}
	        		elseif (isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filter')
		        	{
		        		$lastStr = "controller=gameCategory&action=list&database=ngst&filter=filter";
		        		if($filter == 5)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsNewNSGT($context, $result);
		        		}
		        		elseif($filter == 6)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsPopNSGT($context, $result);
		        		}
		        		elseif($filter == 7)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByRankNSGT($context, $result);
		        		}
		        		elseif($filter == 8)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsFavoriteNSGT($context, $result);
		        		}
		        	}
	        		elseif(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterID')
		        	{
		        		$gameCategoryArr = $gameCategoryService ->getGameCategoryByNameNSGT($context, $result, $filter);
		        	}
	        	}
	        	else 
	        	{
		        	$count = $gameCategoryService->countGameCategoryNSGT($context, $result);
		        	$limit = 30;
		        	$start = $pager->findStart($limit);
		        	$pages = $pager->findPages($count, $limit);
		        	$gameCategoryArr = $gameCategoryService->getFullGameCategoryByLimitNSGT($context, $result, $start, $limit);
		        	$lastStr = "controller=gameCategory&action=list&&database=nsgt";
	        	}
	        }
	        else if($data == 'mmbg')
	        {
	        	$gameCategoryNameArr = $gameCategoryService -> getFullGameCategoryMMBG($context, $result);
	        	if(isset($_POST) && !empty($_POST))
	        	{
		        	$filter = $_POST['filter'];
		        	if(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterParent')
		        	{
			        	$count = $gameCategoryService->countGameCategoryByParentMMBG($context, $result, $filter);
			        	$limit = 100;
			        	$start = $pager->findStart($limit);
			        	$pages = $pager->findPages($count, $limit);
			        	$gameCategoryArr = $gameCategoryService->getGameCategoryByParentMMBG($context, $result, $start, $limit, $filter);
			        	$lastStr = "controller=gameCategory&action=list&database=tpg&filter=filterParent";
		        	}
	        		if (isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filter')
		        	{
		        		$lastStr = "controller=gameCategory&action=list&database=mmbg&filter=filter";
		        		if($filter == 5)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsNewMMBG($context, $result);
		        		}
		        		elseif($filter == 6)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsPopMMBG($context, $result);
		        		}
		        		elseif($filter == 7)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByRankMMBG($context, $result);
		        		}
		        		elseif($filter == 8)
		        		{
		        			$gameCategoryArr = $gameCategoryService->getGameCategoryByIsFavoriteMMBG($context, $result);
		        		}
		        	}
	        		elseif(isset($_GET) && !empty($_GET) && $_GET['filter'] == 'filterID')
		        	{
		        		$gameCategoryArr = $gameCategoryService ->getGameCategoryByNameMMBG($context, $result, $filter);
		        	}
	        	}
	        	else 
	        	{
		        	$count = $gameCategoryService->countGameCategoryMMBG($context, $result);
		        	$limit = 30;
		        	$start = $pager->findStart($limit);
		        	$pages = $pager->findPages($count, $limit);
		        	$gameCategoryArr = $gameCategoryService->getFullGameCategoryByLimitMMBG($context, $result, $start, $limit);
		        	$lastStr = "controller=gameCategory&action=list&&database=mmbg";
	        	}
        	}
        	$this->smarty->assign('data', $data);
       	}
       	else 
       	{
       		$gameCategoryNameArr = $gameCategoryService -> getFullGameCategoryTPG($context, $result);
       		$count = $gameCategoryService->countGameCategoryTPG($context, $result);
	        $limit = 30;
	        $start = $pager->findStart($limit);
	        $pages = $pager->findPages($count, $limit);
       		$gameCategoryArr = $gameCategoryService->getFullGameCategoryByLimitTPG($context, $result, $start, $limit);
       		$lastStr = "controller=gameCategory&action=list&opt=filterDatabase";
       	}
        if(isset($pager) && isset($pages) && isset($lastStr))
        {	               
	        $pageFirst = $pager->findFirst($curpage, $pages, $lastStr);
	        $pagePrev = $pager->findPrev($curpage, $pages, $lastStr);
	        $pageList = $pager->pageList($curpage, $pages, $lastStr);
	        $pageNext = $pager->findNext($curpage, $pages, $lastStr);
	        $pageLast = $pager->findLast($curpage, $pages, $lastStr);
	
	        $this->smarty->assign('pageFirst', $pageFirst);
	        $this->smarty->assign('pagePrev', $pagePrev);
	        $this->smarty->assign('pageList', $pageList);
	        $this->smarty->assign('pageNext', $pageNext);
	        $this->smarty->assign('pageLast', $pageLast);
	       // $this->smarty->assign('gameArr', $gameArr);
        }
        if (isset($gameCategoryArr))
        {
        	$this->smarty->assign('gameCategoryArr', $gameCategoryArr);
        }
        $this->smarty->assign('gameCategoryNameArr', $gameCategoryNameArr);
        $this->smarty->display('list-game-category.tpl');
    }
    
	public function addAction()
    {
    	$_SESSION['timeout'] = time();
        $context = new BaseContext();
        $result = new ServiceResult();
        $gameService = new GameService();
        $gameCategoryService  = new GameCategoryService();
        $gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);
		if(isset($_GET['data']) && $_GET['data'] =='tpg')
		{
			
	        if(isset($_POST) && !empty($_POST))
	        {
	        	if ($_POST["loaigame"] == 3)
		        {
	                $folder = 'offline';
	            }
	            else if($_POST["loaigame"] == 78)
	            {
	            	 $folder = 'kinhdien';
	            }
	        	else if($_POST["loaigame"] == 2 || $_POST["loaigame"] == 156)
	            {
	               $folder = 'online';
	            }
	        	else if($_POST["loaigame"] == 4)
	            {
	               $folder = 'webgame';
	            }
				if($_POST["kieugame"])
				{
					$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
					$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
	           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
	            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
	            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
				}
				else 
				{
					$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
	            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
	            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
	            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
				}
				
				$_POST['unique_name'] = SEO::friendly_url($_POST['name']);      
				     
	            $param = $_POST;
	            $gameCategoryService->insertGameCategoryTPG($context, $result, $param);
	            header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=tpg");
	        }
	        	                	
		}
		else if(isset($_GET['data']) && $_GET['data'] =='cgmb')
		{
			
			if(isset($_POST) && !empty($_POST))
	        {
	        	if ($_POST["loaigame"] == 3)
	            {
	                $folder = 'offline';
	            }
	            else if($_POST["loaigame"] == 78)
	            {
	            	 $folder = 'kinhdien';
	            }
	        	else if($_POST["loaigame"] == 2 || $_POST["loaigame"] == 156)
	            {
	               $folder = 'online';
	            }
	        	else if($_POST["loaigame"] == 4)
	            {
	               $folder = 'webgame';
	            }
				if($_POST["kieugame"])
				{
					$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
					$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
	           		$_POST['mediumImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
	            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
	            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
				}
				else 
				{
					$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
	            	$_POST['mediumImage'] = 'games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
	            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
	            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
				}
				
				$_POST['unique_name'] = SEO::friendly_url($_POST['name']);             
	            $param = $_POST;
	            $gameCategoryService->insertGameCategoryCGMB($context, $result, $param);
	            header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=cgmb");
	        }  
	       
		}
		
    	else if(isset($_GET['data']) && $_GET['data'] =='mmbg')
		{
			
			if(isset($_POST) && !empty($_POST))
	        {
	        	if ($_POST["loaigame"] == 3)
	            {
	                $folder = 'offline';
	            }
	            else if($_POST["loaigame"] == 78)
	            {
	            	 $folder = 'kinhdien';
	            }
	            else if($_POST["loaigame"] == 2 || $_POST["loaigame"] == 156)
	            {
	               $folder = 'online';
	            }
	        	else if($_POST["loaigame"] == 4)
	            {
	               $folder = 'webgame';
	            }
				if($_POST["kieugame"])
				{
					$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
					$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
	           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
	            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
	            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
				}
				else 
				{
					$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
	            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
	            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
	            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
				}
				
				$_POST['unique_name'] = SEO::friendly_url($_POST['name']);             
	            $param = $_POST;
	            $gameCategoryService->insertGameCategoryMMBGAndNSGT($context, $result, $param);
	            header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=mmbg");
	        }
	        	          
		}
		$this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		$this->smarty->display('add-game-category.tpl');		
    }
    
	public function addMobileAction()
    {
    	$_SESSION['timeout'] = time();
        $context = new BaseContext();
        $result = new ServiceResult();
        $gameService = new GameService();
        $gameCategoryService  = new GameCategoryService();
        $gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);		
        if(isset($_POST) && !empty($_POST))
        {
        	if ($_POST["loaigame"] == 3)
            {
                $folder = 'offline';
            }
            else if($_POST["loaigame"] == 78)
            {
            	 $folder = 'kinhdien';
            }
        	else if($_POST["loaigame"] == 2 || $_POST["loaigame"] == 156)
            {
               $folder = 'online';
            }
        	else if($_POST["loaigame"] == 4)
            {
               $folder = 'webgame';
            }
			if($_POST["kieugame"])
			{
				$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
				$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/mobile'.'/'.$_POST['image'];
           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
			}
			else 
			{
				$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'mobile'.'/'.$_POST['image'];
            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
			}
			
			$_POST['unique_name'] = SEO::friendly_url($_POST['name']);      
			     
            $param = $_POST;
            $gameCategoryService->insertGameCategoryMobile($context, $result, $param);
            header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=mobile");
        }
		$this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		$this->smarty->display('add-game-category-mobile.tpl');		
    }
    
	public function addMMBGAction()
    {
    	$_SESSION['timeout'] = time();
        $context = new BaseContext();
        $result = new ServiceResult();
        $gameService = new GameService();
        $gameCategoryService  = new GameCategoryService();
        $gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);		
        if(isset($_POST) && !empty($_POST))
	    {
        	if ($_POST["loaigame"] == 3)
            {
                $folder = 'offline';
            }
            else if($_POST["loaigame"] == 78)
            {
            	 $folder = 'kinhdien';
            }
            else if($_POST["loaigame"] == 2 || $_POST["loaigame"] == 156)
            {
               $folder = 'online';
            }
        	else if($_POST["loaigame"] == 4)
            {
               $folder = 'webgame';
            }
			if($_POST["kieugame"])
			{
				$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
				$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
			}
			else 
			{
				$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
			}
			
			$_POST['unique_name'] = SEO::friendly_url($_POST['name']);             
            $param = $_POST;
            $gameCategoryService->insertGameCategoryMMBG($context, $result, $param);
            header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=mmbg");
        }
		$this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		$this->smarty->display('add-game-category-mymobigame.tpl');		
    }
	
    public function updateAction()
    {
   	 	$_SESSION['timeout'] = time();
        $context = new BaseContext();
        $result = new ServiceResult();
        $gameCategoryService  = new GameCategoryService();
        $seo = new SEO();
		if(isset($_GET['data']) && !empty($_GET['data']))
		{
			$data = $_GET['data'];
			
			if($data == 'tpg')
			{
				$gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);
				if(isset($_GET['id']) && !empty($_GET['id']))
				{
					$id = $_GET['id'];
					$gameCategory = $gameCategoryService->getGameCategoryByIDTPG($context, $result,$id);
				}	
				$image = explode('/',$gameCategory['largeImage']);
		        $loaiGame = $image[1];
		        $kieugameKD = $image[2];
			 	if($image[1] == 'kinhdien')
		        {
		        	$img = $image[4];
		        }
		        else
		        {
		        	$img = $image[3];
		        }
		        $this->smarty->assign('gameCategory', $gameCategory);
		        $this->smarty->assign('img', $img);
		        $this->smarty->assign('kieugameKD', $kieugameKD);
		        $this->smarty->assign('loaiGame', $loaiGame);
		        if(isset($_POST) && !empty($_POST))
		        {
		            if ($_POST["loaigame"] == 3)
		            {
		                $folder = 'offline';
		            }
		            else if($_POST["loaigame"] == 78)
		            {
		            	 $folder = 'kinhdien';
		            }
		        	else if($_POST["loaigame"] == 2)
		            {
		               $folder = 'online';
		            }
		        	else if($_POST["loaigame"] == 4)
		            {
		               $folder = 'webgame';
		            }
					if($_POST["kieugame"])
					{
						$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
		           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
					}
					else 
					{
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
		            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
					}
		            $_POST['id'] = $_POST['id'];
		            $_POST['shortDetail'] = stripslashes($_POST['shortDetail']);
		            $param = $_POST;
		            $gameCategoryService->updateGameCategoryTPG($context, $result, $param);
		          	header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=tpg");
				}
				
		        $this->smarty->assign('data',$data);
		        $this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		        $this->smarty->display('update-game-category.tpl');
			}
			elseif($data == 'mobile')
			{
				$gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);
				if(isset($_GET['id']) && !empty($_GET['id']))
				{
					$id = $_GET['id'];
					$gameCategory = $gameCategoryService->getGameCategoryByIDMobile($context, $result,$id);
				}	
				$image = explode('/',$gameCategory['largeImage']);
		        $loaiGame = $image[1];
		        $kieugameKD = $image[2];
			 	if($image[1] == 'kinhdien')
		        {
		        	$img = $image[4];
		        }
		        else
		        {
		        	$img = $image[3];
		        }
		        $this->smarty->assign('gameCategory', $gameCategory);
		        $this->smarty->assign('img', $img);
		        $this->smarty->assign('kieugameKD', $kieugameKD);
		        $this->smarty->assign('loaiGame', $loaiGame);
		        if(isset($_POST) && !empty($_POST))
		        {
		            if ($_POST["loaigame"] == 3)
		            {
		                $folder = 'offline';
		            }
		            else if($_POST["loaigame"] == 78)
		            {
		            	 $folder = 'kinhdien';
		            }
		        	else if($_POST["loaigame"] == 2)
		            {
		               $folder = 'online';
		            }
		        	else if($_POST["loaigame"] == 4)
		            {
		               $folder = 'webgame';
		            }
					if($_POST["kieugame"])
					{
						$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/mobile'.'/'.$_POST['image'];
		           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
					}
					else 
					{
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'mobile'.'/'.$_POST['image'];
		            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
					}
		            $_POST['id'] = $_POST['id'];
		            $_POST['shortDetail'] = stripslashes($_POST['shortDetail']);
		            $param = $_POST;
		            $gameCategoryService->updateGameCategoryMobile($context, $result, $param);
		          	header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=mobile");
				}
				
		        $this->smarty->assign('data',$data);
		        $this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		        $this->smarty->display('update-game-category.tpl');
			}
			elseif ($data == 'cgmb')
			{
				$gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);
				if(isset($_GET['id']) && !empty($_GET['id']))
				{
					$id = $_GET['id'];
					$gameCategory = $gameCategoryService->getGameCategoryByIDCGMB($context, $result,$id);
				}	
				$image = explode('/',$gameCategory['largeImage']);
		        $loaiGame = $image[1];
		        $kieugameKD = $image[2];
			 	if($image[1] == 'kinhdien')
		        {
		        	$img = $image[4];
		        }
		        else
		        {
		        	$img = $image[3];
		        }
		        
		        $imagex = explode('/',$gameCategory['xlargeImage']);
				if($imagex[1] == 'kinhdien')
		        {
		        	$imgx = $image[4];
		        }
		        else
		        {
		        	$imgx = $image[3];
		        }
		        
		        $this->smarty->assign('gameCategory', $gameCategory);
		        $this->smarty->assign('img', $img);
		        $this->smarty->assign('imgx', $imgx);
		        $this->smarty->assign('kieugameKD', $kieugameKD);
		        $this->smarty->assign('loaiGame', $loaiGame);
		        if(isset($_POST) && !empty($_POST))
		        {
		            if ($_POST["loaigame"] == 3)
		            {
		                $folder = 'offline';
		            }
		            else if($_POST["loaigame"] == 78)
		            {
		            	 $folder = 'kinhdien';
		            }
		        	else if($_POST["loaigame"] == 2)
		            {
		               $folder = 'online';
		            }
		        	else if($_POST["loaigame"] == 4)
		            {
		               $folder = 'webgame';
		            }
					if($_POST["kieugame"])
					{
						$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
		           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
		            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
					}
					else 
					{
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
		            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
		            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
					}
		            $_POST['id'] = $_POST['id'];
		            $_POST['shortDetail'] = stripslashes($_POST['shortDetail']);
		            $param = $_POST;
		            $gameCategoryService->updateGameCategoryCGMB($context, $result, $param);
		          	header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=cgmb");
				}
				
		        $this->smarty->assign('data',$data);
		        $this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		        $this->smarty->display('update-game-category.tpl');
			}
			elseif ($data == 'mmbg')
			{
				$gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);
				if(isset($_GET['id']) && !empty($_GET['id']))
				{
					$id = $_GET['id'];
					$gameCategory = $gameCategoryService->getGameCategoryByIDMMBG($context, $result,$id);
				}	
				$image = explode('/',$gameCategory['largeImage']);
		        $loaiGame = $image[1];
		        $kieugameKD = $image[2];
			 	if($image[1] == 'kinhdien')
		        {
		        	$img = $image[4];
		        }
		        else
		        {
		        	$img = $image[3];
		        }
		        
		        $imagex = explode('/',$gameCategory['xlargeImage']);
				if($imagex[1] == 'kinhdien')
		        {
		        	$imgx = $image[4];
		        }
		        else
		        {
		        	$imgx = $image[3];
		        }
		        
		        $this->smarty->assign('gameCategory', $gameCategory);
		        $this->smarty->assign('img', $img);
		        $this->smarty->assign('imgx', $imgx);
		        $this->smarty->assign('kieugameKD', $kieugameKD);
		        $this->smarty->assign('loaiGame', $loaiGame);
		        if(isset($_POST) && !empty($_POST))
		        {
		            if ($_POST["loaigame"] == 3)
		            {
		                $folder = 'offline';
		            }
		            else if($_POST["loaigame"] == 78)
		            {
		            	 $folder = 'kinhdien';
		            }
		            else if($_POST["loaigame"] == 2)
		            {
		               $folder = 'online';
		            }
		        	else if($_POST["loaigame"] == 4)
		            {
		               $folder = 'webgame';
		            }
					if($_POST["kieugame"])
					{
						$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
		           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
		            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
					}
					else 
					{
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
		            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
		            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
					}
		            $_POST['id'] = $_POST['id'];
		            $_POST['shortDetail'] = stripslashes($_POST['shortDetail']);
		            $param = $_POST;
		            $gameCategoryService->updateGameCategoryMMBG($context, $result, $param);
		          	header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=mmbg");
				}
				
		        $this->smarty->assign('data',$data);
		        $this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		        $this->smarty->display('update-game-category.tpl');
			}
			elseif ($data == 'nsgt')
			{
				$gamekinhdienArr = $gameCategoryService -> getGameCategoryByParentMobile($context, $result, 78);
				if(isset($_GET['id']) && !empty($_GET['id']))
				{
					$id = $_GET['id'];
					$gameCategory = $gameCategoryService->getGameCategoryByIDNSGT($context, $result,$id);
				}	
				$image = explode('/',$gameCategory['largeImage']);
		        $loaiGame = $image[1];
		        $kieugameKD = $image[2];
			 	if($image[1] == 'kinhdien')
		        {
		        	$img = $image[4];
		        }
		        else
		        {
		        	$img = $image[3];
		        }
		        
		        $imagex = explode('/',$gameCategory['xlargeImage']);
				if($imagex[1] == 'kinhdien')
		        {
		        	$imgx = $image[4];
		        }
		        else
		        {
		        	$imgx = $image[3];
		        }
		        
		        $this->smarty->assign('gameCategory', $gameCategory);
		        $this->smarty->assign('img', $img);
		        $this->smarty->assign('imgx', $imgx);
		        $this->smarty->assign('kieugameKD', $kieugameKD);
		        $this->smarty->assign('loaiGame', $loaiGame);
		        if(isset($_POST) && !empty($_POST))
		        {
		            if ($_POST["loaigame"] == 3)
		            {
		                $folder = 'offline';
		            }
		            else if($_POST["loaigame"] == 78)
		            {
		            	 $folder = 'kinhdien';
		            }
		            else if($_POST["loaigame"] == 2)
		            {
		               $folder = 'online';
		            }
		        	else if($_POST["loaigame"] == 4)
		            {
		               $folder = 'webgame';
		            }
					if($_POST["kieugame"])
					{
						$kieugame = SEO::friendly_url_image($_POST["kieugame"]);
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. $kieugame.'/thumbnail'.'/'.$_POST['image'];
		           		$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.$kieugame.'/small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/large'.'/'.$_POST['image'];
		            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.$kieugame.'/xlarge'.'/'.$_POST['xlargeImage'];
					}
					else 
					{
						$_POST['smallImage'] = '/games'.'/'. $folder .'/'. 'thumbnail'.'/'.$_POST['image'];
		            	$_POST['mediumImage'] = '/games'.'/'. $folder .'/'.'small'.'/'.$_POST['image'];
		            	$_POST['largeImage'] = 'games'.'/'. $folder .'/'.'large'.'/'.$_POST['image'];
		            	$_POST['xlargeImage'] = 'games'.'/'. $folder .'/'.'xlarge'.'/'.$_POST['xlargeImage'];
					}
		            $_POST['id'] = $_POST['id'];
		            $_POST['shortDetail'] = stripslashes($_POST['shortDetail']);
		            $param = $_POST;
		            $gameCategoryService->updateGameCategoryNSGT($context, $result, $param);
		          	header("location:".WEB_BASE_URL."/index.php?controller=gameCategory&action=list&database=nsgt");
				}
				
		        $this->smarty->assign('data',$data);
		        $this->smarty->assign('gamekinhdienArr',$gamekinhdienArr);
		        $this->smarty->display('update-game-category.tpl');
			}
		}
		else 
		{
			$this->smarty->display('update-game-category.tpl');
		}
        
    }
}

?>